import os
import simsym
import symtypes
import errno
import model
import signal
import ptypes
import ProcessTable
import HardwareRegisters

class Context(simsym.tstruct(
		ptab	= ProcessTable.ProcessTable,
		sched	= ptypes.LowLevelScheduler,
		hw	= HardwareRegisters.HardwareRegisters
		)):
	def _declare_assumptions(self, assume):
		super(Context, self)._declare_assumptions(assume)
	
	@model.methodwrap(
		ptb = ProcessTable.ProcessTable,
		shd	= ptypes.LowLevelScheduler,
		hwregs	= HardwareRegisters.HardwareRegisters)
	def INIT(self, ptb, shd, hwregs):
		self.ptab	= ptb
		self.sched	= shd
		self.hw		= hwregs
	
	@model.methodwrap()
	def SaveState(self):
		cp = self.sched.CurrentProcess
		pd = self.ptab.DescrOfProcess(cp)
		#simsym.assume(self.procs.contains(pid))
		regs = self.hw.GetGPRegs
		stk = self.hw.GetStackReg
		ip = self.hw.GetIP
		stat = self.hw.GetStatWd
		#pd.SetFullContext(regs, ip, stat, stk)
	
	@model.methodwrap()
	def RestoreState(self):
		cp = self.sched.CurrentProcess
		pd = self.ptab.DescrOfProcess(cp)
	
	@model.methodwrap()
	def SwapOut(self):
		cp = self.sched.CurrentProcess
		pd = self.ptab.DescrOfProcess(cp)
		pd.SetProcessStatusToWaiting
		self.SaveState
		#self.sched.MakeUnready(currentp)
		#self.sched.ScheduleNext
	
	@model.methodwrap()
	def SwapIn(self):
		# TODO
		return 0
	
	@model.methodwrap()
	def SwitchContext(self):
		self.SwapOut
		self.SwapIn
		return 0

model_class = Context
